﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;

namespace LordBlocker
{
    public partial class FrmPrincipal : Form
    {
        private Queue<string> _usuarios;

        public FrmPrincipal()
        {
            InitializeComponent();
        }

        private void FrmPrincipal_Load(object sender, EventArgs e)
        {
            _usuarios = new Queue<string>();

            using (StreamReader reader = new StreamReader("Cache.txt"))
                do
                {
                    _usuarios.Enqueue(reader.ReadLine());
                } while (!reader.EndOfStream);

            EmpezarBloquear();
        }

        private void EmpezarBloquear()
        {
            ProcessStartInfo info = new ProcessStartInfo(System.Configuration.ConfigurationSettings.AppSettings["ProcesoPath"]);
            info.Arguments = _usuarios.Dequeue();

            using (StreamWriter write = new StreamWriter("AnteUltimo.txt", false))
                write.WriteLine(info.Arguments);

            Process.Start(info);
            tmrVerificador.Start();
        }

        private void tmrVerificador_Tick(object sender, EventArgs e)
        {
            tmrVerificador.Stop();
            lblUltimoChequeo.Text = DateTime.Now.ToString();
            Process[] procesos = Process.GetProcesses();

            if (procesos.Where(p => p.ProcessName.Equals("FeizNavegueitor")).Count() == 0)
                EmpezarBloquear();

            tmrVerificador.Start();
        }
    }
}
